/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package my.presentation;

import app.Kucharka;
import boundary.ReceptFacade;
import entities.Recept;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Michal Vachler
 */
@ManagedBean
@SessionScoped
public class ReceptView {
    
    @EJB
    private Kucharka Kucharka;

   // Creates a new field
    private Recept recept;
    
    private int rating;

    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public Recept getRecept() {
        return recept;
    }

    public int getNumberOfRecept() {
       return Kucharka.vratitPocetReceptu();
    }
    
    /**
     * Vrací všechny recepty z databáze
     * @return List<Recept>
     */
    public List<Recept> getAllRecept() {
       return Kucharka.vratitSeznamReceptu();
    }    

    /**
     * Creates a new instance of ReceptView
     */
    public ReceptView() {
    }
    
    public String showReceptDetail(Recept selected){
        recept = selected;
        return "recepty_detail";
    }
    
    public String showReceptEdit(Recept selected){
        recept = selected;
        return "recepty_editace";
    }
    
    public String showReceptNew(){
        recept = null;
        return "recepty_editace";
    }
    
    public String showReceptVareni(Recept selected){
        recept = selected;
        return "recepty_vareni";
    }
    
    public String newRecept(){
            Recept newRecept = new Recept();
        return "recepty";
    }
    
    /**
     * Převodník Map<Ingredience, Mnozstvi> na List
     * @return List<Recept>
     */
    public static List<Map.Entry<?, ?>> toList(Map<?, ?> map) {
        if (map != null){
            return new ArrayList<Map.Entry<?,?>>(map.entrySet());
        } else {
            return null;
        }
    }
    
    
}
